{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Empty(Exception):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['abc', 2, 5]\n",
      "[5]\n"
     ]
    }
   ],
   "source": [
    "class Queue(object):\n",
    "    class _Node(object):\n",
    "        def __init__(self,element,next):\n",
    "            self._element=element\n",
    "            self._next=next\n",
    "            \n",
    "    def __init__(self):\n",
    "        self._head = None\n",
    "        self._tail = None\n",
    "        self._size = 0\n",
    "    def __len__(self):\n",
    "        return self._size\n",
    "    def is_empty(self):\n",
    "        return self._size == 0\n",
    "    def first(self):\n",
    "        if self.is_empty():\n",
    "            raise Empty('Queue is empty')\n",
    "        return self._head._element\n",
    "    def dequeue(self):\n",
    "        if self.is_empty():\n",
    "            raise Empty('Queue is empty')\n",
    "        result = self._head._element\n",
    "        self._head=self._head._next\n",
    "        self._size -=1\n",
    "        if self.is_empty():\n",
    "            self._tail = None\n",
    "        return result\n",
    "    def enqueue(self,e):\n",
    "        node = self._Node(e,None)\n",
    "        if self.is_empty():\n",
    "            self._head= node\n",
    "        else:    \n",
    "            self._tail._next=node\n",
    "        self._tail=node\n",
    "        self._size+=1\n",
    "        \n",
    "    def __repr__(self):\n",
    "        data=[]\n",
    "        walk = self._head\n",
    "        while walk._next is not None:\n",
    "            data.append(walk._element)\n",
    "            walk = walk._next\n",
    "        data.append(walk._element)\n",
    "        return f'{data}'\n",
    "\n",
    "    \n",
    "if __name__=='__main__':\n",
    "    q=Queue()\n",
    "    q.enqueue('abc')\n",
    "    q.enqueue(2) \n",
    "    q.enqueue(5)\n",
    "    print(q)\n",
    "    \n",
    "    q.dequeue() \n",
    "    q.dequeue()\n",
    "    print(q)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
